import * as jsondiffpatch from 'jsondiffpatch'

const diffpatcher = jsondiffpatch.create({
  objectHash: function (data) {
    return data._id || data.id || data.relationId || data.icon
  },

  matchByPosition: false,

  propertyFilter: function (name) {
    return !['eventTransform', 'createTime'].includes(name)
  }
})

export function compareJson (oldData, newData) {
  const delta = diffpatcher.diff(oldData, newData)
  return delta
}
